package com.fanbai.score.user.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.base.BaseActivity;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by acer on 2017/6/3.
 *  收货地址列表或银行卡列表的界面
 *  actStatus =1;收货地址
 *  actStatus =2;银行卡
 */

public class AddressOrBankCardList_Activity extends BaseActivity{

    @BindView(R.id.view_recyclerView)
    RecyclerView mRecyclerView;

    int actStatus;
    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_address_or_bankcard_lsit;
    }

    @Override
    public String getTitleName() {
        int actStatus = getIntent().getExtras().getInt("actStatus");
        if(actStatus == 1){
            return "地址列表";
        }else if(actStatus == 2){
            return "银行卡信息";
        }
        return null;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        actStatus = getIntent().getExtras().getInt("actStatus");
        List<String> dataList = new ArrayList<>();
        dataList.add("hm");
        dataList.add("hm13");
        dataList.add("hm2");
        mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
        int layout = 0;
        if(actStatus == 1){
            layout = R.layout.user_item_addresslist;
        }else if(actStatus == 2){
            layout = R.layout.user_item_bankcardlist;
        }
        mRecyclerView.setAdapter(new CommonAdapter<String>(ctx, layout,
                dataList){
            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                if(actStatus == 1){
                    holder.setText(R.id.userItemAddressInfo_nameAndMobile, ""+s);
                }else if(actStatus == 2){
                    holder.setText(R.id.userItemBankCard_name, ""+s);
                }
            }
        });
    }

    @Override
    protected void initListener() {

    }

    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_add, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item_sort_listview clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_add) {
            if(actStatus == 1){
                jumpToActivity(EditAddress_Activity.class);
            }else if(actStatus == 2){
                jumpToActivity(EditBankCard_Activity.class);

            }
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
